package com.pet.server.ext.action.user;

import java.util.Date;

import net.sf.json.JSONObject;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.BeanToJson;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.PetInfo;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.StringUtil;

public class Petremove extends ActionBase{
	
	public String pet_cate,pet_name,breed,ico_path,sex;
	public Date birthday;
	public Integer id;
	
	public Petremove(){
		 needCheckAuth =true;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		id = NumberUtil.getInteger(params.getFieldValue("pet_id"));
		if(StringUtil.isEmpty(id)){
			throw ApiError.Type.INVALID_PARAM.toException();
		}
	}
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
		PetInfo pet = userService.findPetInfoById(id);
		if(null==pet || !StringUtil.equals(user.user_id, pet.getUser_id())){
			throw ApiError.Type.EXIST_PARAM.toException();
		}
		userService.updatePetInfo4remove(pet);
		Result result = new Result();
		JSONObject data = new JSONObject();
		data.accumulate("message", "删除成功");
		result.put("data", data);
	    return result;
	}
}
